package test;

import static org.junit.Assert.*;
import movement.Location;

import org.junit.*;
import unit.*;
import dispatch.*;
import emergency.*;
import emergency.Fire.Size;
import main.*;

public class useCaseTestRecordEmergency {
	FacadeOperator facade;
	Location justALocation;
	
	DispatchCenter center;
	Garage garage;
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		facade = new FacadeOperator(world);
		
		center = facade.getDispatchCenter();
		garage = center.getGarage();
		justALocation = new Location(10,10,"NameDoesn'tMatter");
	}
	
	@Test
	public void testRecordEmergencyFire(){
		assertEquals(center.getEmergencyboard().getEmergencies().size(),0);
		facade.createFire(justALocation, Severity.SERIOUS, Size.FACILITY, false, 1, 1);
		assertEquals(center.getEmergencyboard().getEmergencies().size(),1);
		assertEquals(center.getEmergencyboard().getEmergencies().get(0).getStateName(),"staterecorded");
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyFireNegativeInjured1(){
		facade.createFire(justALocation, Severity.SERIOUS, Fire.Size.HOUSE, false, -1, 1);
	}

	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyFireNegativeInjured2(){
		facade.createFire(justALocation, Severity.SERIOUS, Fire.Size.HOUSE, false, 1, -1);
	}
	
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyFireNoFireSize(){
		facade.createFire(justALocation, Severity.SERIOUS, null, false, 1, 1);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyFireNoLocation(){
		facade.createFire(null, Severity.SERIOUS, Size.FACILITY, false, 1, 1);
	}

	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyFireNoSeverity(){
		facade.createFire(justALocation, null, Size.FACILITY, false, 1, 1);
	}
	
	@Test
	public void testRecordEmergencyPublicDisturbance(){
		assertEquals(center.getEmergencyboard().getEmergencies().size(),0);
		facade.createPublicDisturbance(justALocation, Severity.SERIOUS, 3);
		assertEquals(center.getEmergencyboard().getEmergencies().size(),1);
		assertEquals(center.getEmergencyboard().getEmergencies().get(0).getStateName(),"staterecorded");
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyPublicDisturbanceNegativePeople(){
		facade.createPublicDisturbance(justALocation, Severity.SERIOUS, -1);
	}

	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyPublicDisturbanceNoLocation(){
		facade.createPublicDisturbance(null, Severity.SERIOUS, 1);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyPublicDisturbanceNoSeverity(){
		facade.createPublicDisturbance(justALocation, null, 1);
	}

	@Test
	public void testRecordEmergencyRobbery(){
		assertEquals(center.getEmergencyboard().getEmergencies().size(),0);
		facade.createRobbery(justALocation, Severity.BENIGN, true,true);
		assertEquals(center.getEmergencyboard().getEmergencies().size(),1);
		assertEquals(center.getEmergencyboard().getEmergencies().get(0).getStateName(),"staterecorded");
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyRobberyNoLocation(){
		facade.createRobbery(null, Severity.BENIGN, true,true);
	}

	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyRobberyNoSeverity(){
		facade.createRobbery(justALocation, null, true,true);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyTrafficAccidenNegativeCars(){
		facade.createTrafficAccident(justALocation, Severity.BENIGN, 1, -1);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyTrafficAccidenNegativePeople(){
		facade.createTrafficAccident(justALocation, Severity.BENIGN, -1, 1);
	}
	
	@Test
	public void testRecordEmergencyTrafficAccident(){
		assertEquals(center.getEmergencyboard().getEmergencies().size(),0);
		facade.createTrafficAccident(justALocation, Severity.BENIGN, 1, 1);
		assertEquals(center.getEmergencyboard().getEmergencies().size(),1);
		assertEquals(center.getEmergencyboard().getEmergencies().get(0).getStateName(),"staterecorded");
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyTrafficAccidentNoLocation(){
		facade.createTrafficAccident(null, Severity.BENIGN, 1, 1);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testRecordEmergencyTrafficAccidentNoSeverity(){
		facade.createTrafficAccident(justALocation, null, 1, 1);
	}	
}
